package MtG.server.components;

import java.util.LinkedList;

/**
 * GameMoves.java is the class that handles the objects needed to be sent to clients. 
 * where all the cards in play will be situated.
 * @author Marek Sirp
 * @author Jaan Sepp
 */
public class GameMoves {
	
	/**
	 * List of objects that need to be transferred.
	 */
	private LinkedList<Object> gameMove = new LinkedList<Object>(); 
	
	/**
	 * @param object Method for adding an object to be sent.
	 */
	public synchronized void addGameMove(Object object) {
		gameMove.add(object);
		this.notifyAll(); 
	}
	
	/**
	 * @return an object that is to be sent if there are any.
	 */
	public synchronized Object getGameMove() { 
		try {
			while (gameMove.isEmpty())
				this.wait(); 
		} catch (InterruptedException e) {}

		Object object = gameMove.getFirst();
		gameMove.removeFirst();
		return object;
	}

}
